/*
 * Copyright (c) 2012 Universidad Antonio de Nebrija.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0.html
 * 
 * Contributors:
 *    Universidad Antonio de Nebrija - initial API, implementation and documentation
 */
package com.nebrija.riif.model.functions;

import com.nebrija.riif.model.Function;
import com.nebrija.riif.model.Util;

/**
 * Represents the e^x function
 * @author asanchep
 *
 */
public class EXPFunction extends Function{

	/** function name */
	public static final String NAME="EXP";
	
	/**
	 * Creates an EXPFunction
	 */
	public EXPFunction() {
		super(EXPFunction.NAME, 1);
	}

	@Override
	protected Object executeFunction(Object... operands) {
		Object op1 = operands[0];
		
		// If the operand is a string, we could not compute it. Return the original function
		if(op1 instanceof String){
			return NAME+"("+op1+")";
		}
		
		//Return e^operands[0]
		return Math.exp(Util.convertToDouble(op1));
	}

}
